package com.emotion.recognition.server.som;

import java.util.List;
import java.util.Random;

import com.emotion.recognition.shared.Emotion;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.gwt.rpc.server.Pair;

public class SomTest {

	public static void main(String[] args) {

		SOM net = SOM.builder().setInputSize(4).setLatticeSize(8)
				.setLearningRate(0.25).setMaxEpochs(1000).setRadius(3)
				.buildClassifier();

		Pair<List<List<Double>>, List<String>> data = createSampleData();

		net.classify(data.getA(), data.getB());

		net.debugPrint();
	}

	private static Pair<List<List<Double>>, List<String>> createSampleData() {
		List<List<Double>> inputs = Lists.newArrayList();
		List<String> categories = Lists.newArrayList();

		Random r = new Random(1234L);

		while (inputs.size() < 20) {
			double d1 = r.nextDouble();
			double d2 = r.nextDouble();
			double d3 = r.nextDouble();
			double d4 = r.nextDouble();

			Emotion category = Emotion.NONE;

			if (d1 > 0.75 && d2 < 0.10 && d3 < 0.10 && d4 < 0.10) {
				category = Emotion.ASTONISHED; // 0001
			} else if (d2 > 0.75 && d1 < 0.10 && d3 < 0.10 && d4 < 0.10) {
				category = Emotion.CALM; // 0010
			} else if (d3 > 0.75 && d2 < 0.10 && d1 < 0.10 && d4 < 0.10) {
				category = Emotion.SAD; // 0100
			} else if (d4 > 0.75 && d2 < 0.10 && d3 < 0.10 && d1 < 0.10) {
				category = Emotion.SMILING; // 1000
			}

			if (category != Emotion.NONE) {
				inputs.add(ImmutableList.of(d1, d2, d3, d4));
				categories.add(category.toString());
			}
		}

		return new Pair<List<List<Double>>, List<String>>(inputs, categories);
	}
}
